package com.cloud.bssp.admin.wanda.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bssp.admin.wanda.dto.ClassesDTO;
import com.cloud.bssp.admin.wanda.entity.ClassesDO;
import com.cloud.bssp.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 班次
 * Create Date: 2021-07-04T18:48:50.805
 * Modified By：<br>
 * Modified Date：<br>
 * Why & What is modified：<br>
 *
 * @author weirx
 * @version 1.0
 */
@Component
public class ClassesDoConvert {

    /**
     * DtoToDo
     *
     * @param classesDTO
     * @return
     */
    public static ClassesDO dtoToDo(ClassesDTO classesDTO) {
            ClassesDO classesDO = new ClassesDO();
        BeanCopierUtil.copy(classesDTO, classesDO);
        return classesDO;
    }

    /**
     * DoToDto
     *
     * @param classesDO
     * @return
     */
    public static ClassesDTO doToDto(ClassesDO classesDO) {
            ClassesDTO classesDTO = new ClassesDTO();
        BeanCopierUtil.copy(classesDO, classesDTO);
        return classesDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<ClassesDTO> pageConvert(Page<ClassesDO> pageDO) {
        List<ClassesDTO> list = listConvert(pageDO.getRecords());
        Page<ClassesDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<ClassesDTO> listConvert(List<ClassesDO> listDO) {
        List<ClassesDTO> list = new ArrayList<>();
            ClassesDTO classesDTO;
        for (ClassesDO classesDO : listDO) {
                classesDTO = new ClassesDTO();
            BeanCopierUtil.copy(classesDO, classesDTO);
            list.add(classesDTO);
        }
        return list;
    }
}